<%@page import="school.entity.Student"%>
<%@page import="school.dao.StudentDaoI"%>
<%@page import="school.dao.StudentDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'students.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script src="js/jquery-3.3.1.min.js"></script>
	
  </head>
  
  <body>
  <jsp:include page="checkLogin.jsp"></jsp:include>
  <a href="addStudent.jsp">新生注册</a>
    <table align="center" width="80%" border="1" cellpadding="0" cellspacing="0">
    <tr>
    <td>学号</td><td>姓名</td><td>手机号</td><td>性别</td><td>操作</td>
    </tr>
    <%
    	
    	int p=1;
    	try{
    		p=Integer.parseInt(request.getParameter("pageNo"));
    	}catch(Exception e){}//忽略异常
    	
    	StudentDaoI sdao=new StudentDao();
    	int totalpage=sdao.findTotalPages();
    	List<Student> list=sdao.search(p);
    	for(Student s:list){
     %>
     <tr>
     	<td><%=s.getStuno() %></td>
     	<td><%=s.getSname() %></td>
     	<td><%=s.getTelephone() %></td>
     	<td><%=s.getSex() %></td>
     	<td><a onclick="return confirm('您是真的要删除[<%=s.getSname() %>]吗？')" href="studentDel.jsp?no=<%=s.getStuno()%>">删除</a>
     		<a href="toUpdateStudent.jsp?no=<%=s.getStuno()%>">修改</a>
     	</td>
     </tr>
     <%} %>
     </table>
     <p>
     <a href="students2.jsp?pageNo=1">首页</a>   
     <%if(p>1){ %>
  	<a href="students2.jsp?pageNo=<%=p-1%>">上一页</a>   
     &nbsp;
     
     <%}
     if(p<totalpage){
      %>
    <a href="students2.jsp?pageNo=<%=p+1%>">下一页</a> 
    <%} %>
     &nbsp;
     <input type="number" style="width:40px" name="pageNo" value="<%=p%>"/><input type="button" value="GO" id="go"/>
     
   &nbsp;
    <a href="students2.jsp?pageNo=<%=totalpage%>">最后一页</a>  
     共<%=totalpage%>页</p>
     
     <script>
		$(function(){
			
			$("#go").click(function(){
				 var n=$(this).prev().val();
				 if(n<1)n=1;
				 if(n><%=totalpage%>)
				 	n=<%=totalpage%>;
				 	
				location='students2.jsp?pageNo='+n;
			});
		});
	</script>
	
  </body>
</html>
